package com.lyouu.dataminer.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import com.lyouu.dataminer.db.DbConstants;
import com.lyouu.dataminer.factory.MysqlDbFactory;
import com.lyouu.dataminer.util.Constants;

public class MdSubjectattDao {
	public void insert(int sid, int categoryAttId,
			List<Integer> tourAreaAttidList, String departCountry)
			throws SQLException {
		Connection conn =  MysqlDbFactory.getConnection(DbConstants.DB_LYOUU);
		String sql = "INSERT INTO md_subjectatt" + "(sid,attid,type,att_catid)"
				+ " VALUES (?,?,?,?)";
		PreparedStatement stmt = conn.prepareStatement(sql);
		stmt.setInt(1, sid);
		stmt.setInt(2, categoryAttId);
		stmt.setString(3, "category");
		stmt.setInt(4, 0);
		stmt.executeUpdate();

		stmt.setInt(1, sid);
		stmt.setInt(2, Constants.MD_SUBJECTATT_AREA_ATTID_EUROPE);
		stmt.setString(3, "area");
		stmt.setInt(4, 0);
		stmt.executeUpdate();
		stmt.setInt(1, sid);
		stmt.setInt(2, Constants.MD_SUBJECTATT_AREA_ATTID_VIRTUAL_COUNTRY);
		stmt.setString(3, "area");
		stmt.setInt(4, 0);
		stmt.executeUpdate();

		// 添加旅游地区
		for (int i = 0; i < tourAreaAttidList.size(); i++) {
			stmt.setInt(1, sid);
			stmt.setInt(2, tourAreaAttidList.get(i));
			stmt.setString(3, "att");
			stmt.setInt(4, 1);
			stmt.executeUpdate();
		}
		// 添加出发国家
		stmt.setInt(1, sid);
		stmt.setInt(2, Integer.valueOf(departCountry));
		stmt.setString(3, "att");
		stmt.setInt(4, 2);
		stmt.executeUpdate();
	}
}
